﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Data;

namespace QuanLyShopCD.BL
{
    class tinh_qlcd
    {
        AcessData con;
        TextBox txtma, txtten, txtdg;
        DataGridView grv1;
        ComboBox cb1;
        DataTable tb;
        public tinh_qlcd(TextBox tbid,TextBox tbcd,ComboBox cb,TextBox tbdg , DataGridView dg)
        {
            con = new AcessData();
            this.txtdg = tbdg;
            this.txtma = tbid;
            this.txtten = tbcd;
            this.cb1 = cb;
            this.grv1 = dg;
        }
        public void hienthi ()
        {
            con.Open();
            tb = con.Execute_ps("PS_SHOPCD");
            grv1.DataSource = tb;
            con.Close();
            Refesh();
        }
        void Refesh()
        {
            txtten.DataBindings.Clear();
            txtma.DataBindings.Clear();
            txtdg.DataBindings.Clear();
            cb1.DataBindings.Clear();
            txtten.DataBindings.Add("Text", tb, "TenLoai");
            txtma.DataBindings.Add("Text", tb, "MaCD");
            txtdg.DataBindings.Add("Text", tb, "DonGiaThue");
            cb1.DataBindings.Add("SelectedValue", tb, "MaDM");
        }
        public void them() 
        {
            con.Open();
            SqlParameter[] pr = { new SqlParameter("MaCD",txtma.Text), new SqlParameter("TenLoai",txtten.Text), new SqlParameter("DonGiaThue",txtdg.Text), new SqlParameter("MaDM",cb1.SelectedValue) };
            tb = con.Execute_ps("PS_NHAP_SHOPCD",pr);
            grv1.DataSource = tb;
            con.Close();
            Refesh();
        }
        public void sua() 
        {
            con.Open();
            SqlParameter[] pr = { new SqlParameter("MaCD", txtma.Text), new SqlParameter("TenLoai", txtten.Text), new SqlParameter("DonGiaThue", txtdg.Text), new SqlParameter("MaDM", cb1.SelectedValue) };
            tb = con.Execute_ps("PS_SUA_SHOPCD", pr);
            grv1.DataSource = tb;
            con.Close();
            Refesh();
        }
        public void xoa()
        {
            con.Open();
            SqlParameter[] pr = { new SqlParameter("MaCD", txtma.Text) };
            tb = con.Execute_ps("PS_XOA_SHOPCD", pr);
            grv1.DataSource = tb;
            con.Close();
            Refesh();
        }
    }

}
